package com.zx.Servlet;

import com.google.gson.Gson;
import com.zx.Moudel.Queue;
import com.zx.Service.UserService;
import com.zx.Service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * com.zx.Servlet
 * 26832
 * zx
 * &#064;description: 查看预约结果，预约成功，调用这个显示预约结果
 * &#064;author: lxm
 * SelectQueueServlet
 * &#064;create: 2024-06-22 16:47
 **/
@WebServlet("/selectQueue")
public class SelectQueueServlet extends HttpServlet {
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  doPost(req, resp);
 }

 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  //获取idcard和vaccine
  req.setCharacterEncoding("utf-8");
  resp.setCharacterEncoding("utf-8");
//  HttpSession session = req.getSession();
//  String idcard = (String) session.getAttribute("idcard");
//  String vaccine = (String) session.getAttribute("vaccine");
  String idcard = req.getParameter("idcard");
  System.out.println("selectQueue:"+idcard);
  Queue queue = new Queue();
  UserService userService = new UserServiceImpl();
  List<Queue> list = new ArrayList<>();
   list= userService.selectAllQueue(idcard,"-1");
  String json = "";
  Gson gson = new Gson();
  json = gson.toJson(list);
  resp.getWriter().write(json);//把数据包装为json格式返回给前端页面
 }
}
